package net.lab1024.sa.admin.module.business.category.domain.dto;

import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import net.lab1024.sa.admin.common.EnumConverter;
import net.lab1024.sa.admin.module.business.category.domain.entity.User;
import org.springframework.beans.BeanUtils;

@Data
public class UserExportDTO {
    @ExcelProperty("姓名")
    private String name;

    @ExcelProperty("学号")
    private String userCode;

    @ExcelProperty("班级")
    private String className;

    @ExcelProperty("手机号")
    private String phone;

    @ExcelProperty("邮箱")
    private String email;

    @ExcelProperty("状态")
    private String statusStr;

    @ExcelProperty("职务")
    private String positionStr;

    @ExcelProperty("角色")
    private String roleStr;

    @ExcelProperty("学院")
    private String collegeStr;

    // 转换方法
    public static UserExportDTO fromEntity(User user) {
        UserExportDTO dto = new UserExportDTO();
        BeanUtils.copyProperties(user, dto);

        // 状态转换
        dto.setStatusStr(convertStatus(user.getStatus()));
        // 职务转换
        dto.setPositionStr(convertPosition(user.getPosition()));
        // 角色转换
        dto.setRoleStr(convertRole(user.getRole()));
        // 学院转化
        dto.setCollegeStr(EnumConverter.convertCollegeCodeToName(user.getCollege()));

        return dto;
    }

    private static String convertStatus(Integer status) {
        switch (status) {
            case 0:
                return "禁用";
            case 1:
                return "正常";
            default:
                return "未知";
        }
    }

    private static String convertPosition(Integer position) {
        switch (position) {
            case 0:
                return "学生";
            case 1:
                return "老师";
            default:
                return "";
        }
    }

    private static String convertRole(Integer role) {
        switch (role) {
            case 0:
                return "管理员";
            case 1:
                return "普通用户";
            default:
                return "";
        }
    }
}